<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="./css/logon.css">
    <link rel="stylesheet" href="./css/iconfont-1.css">
</head>
<body>
    <div class="head">
        <div class="head1">
            <div class="imgbox">
                <img src="./img/log1.png" alt="">
            </div>
            <a href="./index.html" target="_blank"><div class="sy">首页</div></a>
            <div class="lx">
                热线 : 400-9993-513
            </div>
        </div>
    </div>

    <div class="life">
        <div class="life1">
            <div class="imgbos">
                <img src="./img/log2.jpg" alt="">
            </div>

            <div class="logon1">
                <div class="on">
                    <div class="on1">
                        登录
                    </div>
                    <div class="on2">
                        没有账号？&nbsp;
                        <a href="./regst.html"><span>点击注册</span></a>
                    </div>
                </div>

                <div class="account">
                    <span class="iconfont icon-renxiang accountp"></span>
                    <span>
                        <input type="text" class="accountin">
                    </span>
                </div>
                <div class="pass">
                    <span class="iconfont icon-bianzu passp"></span>
                    <span>
                        <input type="text" class="passin">
                    </span>
                </div>

                
                <div class="record">
                    登&nbsp;&nbsp;&nbsp;录
                </div>
                <span class="msg"></span>
            </div>
        </div>
    </div>

    <div class="foot">
        <div class="foot1">
            <ul class="foot_wk">
                <li>关于我们 <span> / </span> &nbsp;</li>
                <li> 配送政策 <span> / </span> &nbsp;</li>
                <li> 招才纳贤 <span> / </span> &nbsp;</li>
                <li> 帮助中心 <span> / </span> &nbsp;</li>
                <li> 联系我们 <span> / </span> &nbsp;</li>
                <li> 招商加盟 <span> / </span> &nbsp;</li>
                <li> 网站地图 <span> / </span> &nbsp;</li>
                <li> 词条部落</li>
            </ul><br>
            <p>Copyright 2016, 茶七网 TEA7.COM</p>
            <p>增值电信业务经营许可证 : B1.B2-20160011 &nbsp;&nbsp;&nbsp; 闽CP备14011677号-2</p>
            <p>服务时间 : 08:30-21:00 &nbsp;客服热线:400-9993-513（温馨提示 : 请您核对无误后拨出，谢谢！）</p>
            <span><img src="https://rr.knet.cn/static/images/logo/cnnic.png" alt=""></span>
            <span><img src="./img/cert.png" alt=""></span>
        </div>
        <div class="foot2">
            <div class="bos2">
                <img src="./img/guanzhu_weixin_90.jpg" class="imgbos2">
                <p><img src="./img/weixin.png" class="imgbos1"></p>
                <p class="imgbos3">扫描关注微信公众号</p>
            </div>
            <div class="bos2">
                <img src="./img/erweima.jpg" class="imgbos2">
                <p class="imgbos4">APP</p>
                <p class="imgbos3">扫描关注微信公众号</p>
            </div>
        </div>
    </div>
</body>
</html>
<script src="ajax-promise.js"></script>
<script>
    class login{
        constructor(){
            this.tel = document.querySelector(".accountin");
            this.pass = document.querySelector(".passin");
            this.record = document.querySelector(".record");
            this.msg = document.querySelector(".msg");

            this.url = "http://api.icodeilife.cn:81/user";

            this.addevent();
        }

        addevent(){
            var that = this;
            this.record.onclick = function(){
                if(that.tel.value == "" || that.pass.value == ""){
                    that.msg.innerHTML = "请输入";
                }else{

                    that.t = that.tel.value;
                    that.p = that.pass.value;
    
                    that.load();
                }

            }
        }

        load(){
            ajax({
                url:this.url,
                data:{
                    type:"login",
                    user:this.t,
                    pass:this.p
                }
            }).then((res)=>{
                this.res = JSON.parse(res);

                this.display();
            })
        }

        display(){
            switch(this.res.code){
                case 0:
                    this.msg.innerHTML = this.res.msg + ",2秒后到注册";
                    setTimeout(() => {
                        location.href = "regst.html"
                    }, 2000);
                    break;
                case 1:
                    this.msg.innerHTML = "登录成功 2秒后到首页";
                    setTimeout(() => {
                        location.href = "index.html";
                    }, 2000);
                    sessionStorage.setItem("usermsg",JSON.stringify(this.res.msg));
                    break;
                case 2:
                    this.msg.innerHTML = this.res.msg + "，请输入";
                    this.user.value = this.pass.value = "";
                    this.user.focus();
            }
        }
    }


    new login();
</script>